#include "IntroState.h"
#include "rcore.h"


IntroState IntroState::mIntroState;

void IntroState::enter()
{
	//Make sure you never use any renderer calls here.
	//This portion of code happens before the start
	//of the render engine. I may create a "postEnter"
	//pure virtual function for the state class that
	//will be called once the render engine is
	//initialized.

	//Get Input Manager
	mInputManager = InputManager::getSingletonPtr();
	mRenderCore = RenderCore::getSingletonPtr();

	//Not sure about this, but here's the idea
	//The Object Manager will need to clear its
	//renderables database at the enter of each
	//state. It will then fill up with renderables
	//that are appropriate for this particular
	//state. For example, in the Intro state, the
	//Object Manager will clear all data currently
	//in its database and fill up the renderables
	//with menu objects and such.

	//mObjectManager = ObjectManager::getSingletonPtr();
	//mObjectManager->ClearDB();

	//init any booleans
	mExitGame = false;

	// Now may be a good time to build the menu...

}

void IntroState::exit()
{
	//Clean up
}

bool IntroState::FrameFunc()
{
	// Temporary code used for testing the state manager
	// without an Object manager. Once the ObjectManager
	// is finished, this should be replaced by a call to
	// the OM that returns the list of renderable objects
	if (!obj1)
	{
		obj1 = new RenderObject();
		mRenderCore->registerObj(obj1);
	}
	// End temporary code

	// Check the state of the input devices so that we know
	// if we need to call any of the input functions.
	//
	// Note: This only works on buffered inputs.
	mInputManager->capture();
	dt = RenderCore::getSingletonPtr()->GetDelta();

	// Using unbuffered keys here
	using namespace OIS;
	if ( mInputManager->getKeyboard()->isKeyDown(KC_W) )
		obj1->setDy( -(dt*obj1->getSpeed()) );
	if ( mInputManager->getKeyboard()->isKeyDown(KC_S) )
		obj1->setDy( dt*obj1->getSpeed() );
	if ( mInputManager->getKeyboard()->isKeyDown(KC_D) )
		obj1->setDx( dt*obj1->getSpeed() );
	if ( mInputManager->getKeyboard()->isKeyDown(KC_A) )
		obj1->setDx( -(dt*obj1->getSpeed()) );

	// Update the object coordinates. This will be replaced
	// by the OM's global update command.
	obj1->updateCoords();

	//Deal with any bools that get flagged
	//Will be where our change state and
	//exit code lives. All other code lives
	//with the input functions.

	if (mExitGame)
		return true;

	return false;
}

void IntroState::pause()
{
	//no pause state for intro
}

void IntroState::resume()
{
	//no pause state for intro
}

void IntroState::keyPressed( const OIS::KeyEvent &e )
{
	using namespace OIS;

	switch (e.key)
	{
		// Exit the game
		case KC_ESCAPE:
			mExitGame = true;
			break;
		default:
			break;
	}

	// Updates object coordinates. Should be
	// replaced by the OM's global update.
	obj1->updateCoords();
}

void IntroState::keyReleased( const OIS::KeyEvent &e )
{

}

void IntroState::mouseMoved( const OIS::MouseEvent &e )
{

}

void IntroState::mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{

}

void IntroState::mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id )
{

}

void IntroState::buttonPressed( const OIS::JoyStickEvent &e, int val)
{

}

void IntroState::buttonReleased( const OIS::JoyStickEvent &e, int val)
{

}

void IntroState::axisMoved( const OIS::JoyStickEvent &e, int val)
{

}
